{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np # 数据处理最重要的模块\n",
    "import pandas as pd # 数据处理最重要的模块\n",
    "import scipy.stats as stats # 统计模块\n",
    "from datetime import datetime # 时间模块\n",
    "import scipy\n",
    "# import pymysql  # 导入数据库模块\n",
    "import statsmodels.api as sm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "rawdata1 = pd.read_excel('Lecture 2 p2p lending platforms.xlsx')\n",
    "rawdata2 = pd.read_excel('Lecture 2 Renrendai loans.xlsx')\n",
    "data1 = rawdata1[['OnlineTime_YMD','Bankrupt_WDZJ','Collapse', 'Benign','Fraud','RegCapital','Background','Capitaldeposit','Obtaininvest','Joinasso','Autobid','Transright','Riskdeposit','Thirdguarantee']]\n",
    "data2 = rawdata2[['DEFAULT', 'INTEREST','BIDS','AMOUNT','CREDIT','HOUSE','CAR','HOUSE_L','CAR_L','EDUCATION','WORKTIME','INCOME','AGE']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OnlineTime_YMD      0\n",
       "Bankrupt_WDZJ     218\n",
       "Collapse            0\n",
       "Benign            218\n",
       "Fraud             218\n",
       "RegCapital          0\n",
       "Background          0\n",
       "Capitaldeposit      0\n",
       "Obtaininvest       32\n",
       "Joinasso           32\n",
       "Autobid             0\n",
       "Transright          0\n",
       "Riskdeposit        32\n",
       "Thirdguarantee     32\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查是否有缺失值\n",
    "missing1 = data1.isnull().sum()\n",
    "missing1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DEFAULT      0\n",
       "INTEREST     0\n",
       "BIDS         0\n",
       "AMOUNT       0\n",
       "CREDIT       0\n",
       "HOUSE        0\n",
       "CAR          0\n",
       "HOUSE_L      0\n",
       "CAR_L        0\n",
       "EDUCATION    4\n",
       "WORKTIME     6\n",
       "INCOME       2\n",
       "AGE          0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "missing2 = data2.isnull().sum()\n",
    "missing2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OnlineTime_YMD</th>\n",
       "      <th>Bankrupt_WDZJ</th>\n",
       "      <th>Collapse</th>\n",
       "      <th>Benign</th>\n",
       "      <th>Fraud</th>\n",
       "      <th>RegCapital</th>\n",
       "      <th>Background</th>\n",
       "      <th>Capitaldeposit</th>\n",
       "      <th>Obtaininvest</th>\n",
       "      <th>Joinasso</th>\n",
       "      <th>Autobid</th>\n",
       "      <th>Transright</th>\n",
       "      <th>Riskdeposit</th>\n",
       "      <th>Thirdguarantee</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20140519</td>\n",
       "      <td>20170413.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20151231</td>\n",
       "      <td>20170201.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20150504</td>\n",
       "      <td>20161201.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20180310</td>\n",
       "      <td>20180615.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20180320</td>\n",
       "      <td>20180724.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>20150609</td>\n",
       "      <td>20160817.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>20150510</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>20150626</td>\n",
       "      <td>20151019.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>20141101</td>\n",
       "      <td>20160817.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>20140201</td>\n",
       "      <td>20150416.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     OnlineTime_YMD  Bankrupt_WDZJ  Collapse  Benign  Fraud  RegCapital  \\\n",
       "0          20140519     20170413.0         1     0.0    0.0       500.0   \n",
       "1          20151231     20170201.0         1     0.0    0.0       500.0   \n",
       "2          20150504     20161201.0         1     0.0    0.0       500.0   \n",
       "3          20180310     20180615.0         1     0.0    0.0       500.0   \n",
       "4          20180320     20180724.0         1     0.0    1.0         5.0   \n",
       "..              ...            ...       ...     ...    ...         ...   \n",
       "995        20150609     20160817.0         1     0.0    0.0       100.0   \n",
       "996        20150510            NaN         0     NaN    NaN       100.0   \n",
       "997        20150626     20151019.0         1     0.0    1.0       500.0   \n",
       "998        20141101     20160817.0         1     0.0    0.0       100.0   \n",
       "999        20140201     20150416.0         1     0.0    0.0        50.0   \n",
       "\n",
       "    Background  Capitaldeposit  Obtaininvest  Joinasso  Autobid  Transright  \\\n",
       "0          民营系               0           0.0       1.0        0           0   \n",
       "1          民营系               0           0.0       0.0        0           0   \n",
       "2          民营系               0           0.0       0.0        1           1   \n",
       "3          民营系               0           0.0       0.0        0           0   \n",
       "4          民营系               0           0.0       0.0        0           0   \n",
       "..         ...             ...           ...       ...      ...         ...   \n",
       "995        民营系               0           0.0       0.0        0           0   \n",
       "996        民营系               0           0.0       0.0        1           0   \n",
       "997        民营系               0           0.0       0.0        1           0   \n",
       "998        民营系               0           0.0       0.0        0           0   \n",
       "999        民营系               0           0.0       0.0        0           0   \n",
       "\n",
       "     Riskdeposit  Thirdguarantee  \n",
       "0            0.0             0.0  \n",
       "1            0.0             0.0  \n",
       "2            0.0             0.0  \n",
       "3            0.0             0.0  \n",
       "4            0.0             0.0  \n",
       "..           ...             ...  \n",
       "995          0.0             0.0  \n",
       "996          0.0             0.0  \n",
       "997          0.0             0.0  \n",
       "998          0.0             0.0  \n",
       "999          0.0             0.0  \n",
       "\n",
       "[1000 rows x 14 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OnlineTime_YMD      int64\n",
       "Bankrupt_WDZJ     float64\n",
       "Collapse            int64\n",
       "Benign            float64\n",
       "Fraud             float64\n",
       "RegCapital        float64\n",
       "Background         object\n",
       "Capitaldeposit      int64\n",
       "Obtaininvest      float64\n",
       "Joinasso          float64\n",
       "Autobid             int64\n",
       "Transright          int64\n",
       "Riskdeposit       float64\n",
       "Thirdguarantee    float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "表1数据有1000条，考虑到由于“Benign”和“Fraud”是和“Collapse”有关的，且缺失值相等，因此后续会进行异质性检验；对于其他缺失值，先看看对样本数量产生多大影响，如果影响不大就删除缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OnlineTime_YMD</th>\n",
       "      <th>Bankrupt_WDZJ</th>\n",
       "      <th>Collapse</th>\n",
       "      <th>Benign</th>\n",
       "      <th>Fraud</th>\n",
       "      <th>RegCapital</th>\n",
       "      <th>Background</th>\n",
       "      <th>Capitaldeposit</th>\n",
       "      <th>Obtaininvest</th>\n",
       "      <th>Joinasso</th>\n",
       "      <th>Autobid</th>\n",
       "      <th>Transright</th>\n",
       "      <th>Riskdeposit</th>\n",
       "      <th>Thirdguarantee</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20140519</td>\n",
       "      <td>20170413.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20151231</td>\n",
       "      <td>20170201.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20150504</td>\n",
       "      <td>20161201.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20180310</td>\n",
       "      <td>20180615.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20180320</td>\n",
       "      <td>20180724.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>20150609</td>\n",
       "      <td>20160817.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>20150510</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>20150626</td>\n",
       "      <td>20151019.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>20141101</td>\n",
       "      <td>20160817.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>20140201</td>\n",
       "      <td>20150416.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>民营系</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>968 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     OnlineTime_YMD  Bankrupt_WDZJ  Collapse  Benign  Fraud  RegCapital  \\\n",
       "0          20140519     20170413.0         1     0.0    0.0       500.0   \n",
       "1          20151231     20170201.0         1     0.0    0.0       500.0   \n",
       "2          20150504     20161201.0         1     0.0    0.0       500.0   \n",
       "3          20180310     20180615.0         1     0.0    0.0       500.0   \n",
       "4          20180320     20180724.0         1     0.0    1.0         5.0   \n",
       "..              ...            ...       ...     ...    ...         ...   \n",
       "995        20150609     20160817.0         1     0.0    0.0       100.0   \n",
       "996        20150510            NaN         0     NaN    NaN       100.0   \n",
       "997        20150626     20151019.0         1     0.0    1.0       500.0   \n",
       "998        20141101     20160817.0         1     0.0    0.0       100.0   \n",
       "999        20140201     20150416.0         1     0.0    0.0        50.0   \n",
       "\n",
       "    Background  Capitaldeposit  Obtaininvest  Joinasso  Autobid  Transright  \\\n",
       "0          民营系               0           0.0       1.0        0           0   \n",
       "1          民营系               0           0.0       0.0        0           0   \n",
       "2          民营系               0           0.0       0.0        1           1   \n",
       "3          民营系               0           0.0       0.0        0           0   \n",
       "4          民营系               0           0.0       0.0        0           0   \n",
       "..         ...             ...           ...       ...      ...         ...   \n",
       "995        民营系               0           0.0       0.0        0           0   \n",
       "996        民营系               0           0.0       0.0        1           0   \n",
       "997        民营系               0           0.0       0.0        1           0   \n",
       "998        民营系               0           0.0       0.0        0           0   \n",
       "999        民营系               0           0.0       0.0        0           0   \n",
       "\n",
       "     Riskdeposit  Thirdguarantee  \n",
       "0            0.0             0.0  \n",
       "1            0.0             0.0  \n",
       "2            0.0             0.0  \n",
       "3            0.0             0.0  \n",
       "4            0.0             0.0  \n",
       "..           ...             ...  \n",
       "995          0.0             0.0  \n",
       "996          0.0             0.0  \n",
       "997          0.0             0.0  \n",
       "998          0.0             0.0  \n",
       "999          0.0             0.0  \n",
       "\n",
       "[968 rows x 14 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "reg_data1=data1.dropna(subset=['Obtaininvest','Joinasso','Riskdeposit','Thirdguarantee'])\n",
    "reg_data1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可见，共有968条数据，缺失值影响不大。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEFAULT</th>\n",
       "      <th>INTEREST</th>\n",
       "      <th>BIDS</th>\n",
       "      <th>AMOUNT</th>\n",
       "      <th>CREDIT</th>\n",
       "      <th>HOUSE</th>\n",
       "      <th>CAR</th>\n",
       "      <th>HOUSE_L</th>\n",
       "      <th>CAR_L</th>\n",
       "      <th>EDUCATION</th>\n",
       "      <th>WORKTIME</th>\n",
       "      <th>INCOME</th>\n",
       "      <th>AGE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>9</td>\n",
       "      <td>3000</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>8</td>\n",
       "      <td>3000</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>8</td>\n",
       "      <td>3000</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>8.8</td>\n",
       "      <td>11</td>\n",
       "      <td>3000</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>15</td>\n",
       "      <td>5000</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9995</th>\n",
       "      <td>1</td>\n",
       "      <td>11.0</td>\n",
       "      <td>1</td>\n",
       "      <td>7000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9996</th>\n",
       "      <td>0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>1</td>\n",
       "      <td>10000</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9997</th>\n",
       "      <td>0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>18</td>\n",
       "      <td>17000</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9998</th>\n",
       "      <td>0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>8</td>\n",
       "      <td>10000</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9999</th>\n",
       "      <td>0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>7</td>\n",
       "      <td>6000</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10000 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      DEFAULT  INTEREST  BIDS  AMOUNT  CREDIT  HOUSE  CAR  HOUSE_L  CAR_L  \\\n",
       "0           0       5.0     9    3000       7      1    1        1      1   \n",
       "1           0      18.0     8    3000       3      0    0        0      0   \n",
       "2           0      12.0     8    3000       3      0    0        0      0   \n",
       "3           0       8.8    11    3000       7      1    1        1      1   \n",
       "4           0      15.0    15    5000       7      0    1        0      0   \n",
       "...       ...       ...   ...     ...     ...    ...  ...      ...    ...   \n",
       "9995        1      11.0     1    7000       1      1    0        0      0   \n",
       "9996        0      11.0     1   10000       3      0    0        0      0   \n",
       "9997        0      11.0    18   17000       3      1    0        1      0   \n",
       "9998        0      12.0     8   10000       2      0    0        0      0   \n",
       "9999        0       9.0     7    6000       3      1    1        0      0   \n",
       "\n",
       "      EDUCATION  WORKTIME  INCOME  AGE  \n",
       "0           3.0       2.0     6.0   33  \n",
       "1           3.0       4.0     4.0   37  \n",
       "2           3.0       4.0     4.0   37  \n",
       "3           3.0       2.0     6.0   33  \n",
       "4           3.0       2.0     3.0   33  \n",
       "...         ...       ...     ...  ...  \n",
       "9995        3.0       4.0     3.0   36  \n",
       "9996        1.0       2.0     4.0   28  \n",
       "9997        3.0       2.0     3.0   28  \n",
       "9998        2.0       1.0     3.0   30  \n",
       "9999        3.0       4.0     4.0   34  \n",
       "\n",
       "[10000 rows x 13 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "表2有一万条数据，且缺失值较少，直接删去缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEFAULT</th>\n",
       "      <th>INTEREST</th>\n",
       "      <th>BIDS</th>\n",
       "      <th>AMOUNT</th>\n",
       "      <th>CREDIT</th>\n",
       "      <th>HOUSE</th>\n",
       "      <th>CAR</th>\n",
       "      <th>HOUSE_L</th>\n",
       "      <th>CAR_L</th>\n",
       "      <th>EDUCATION</th>\n",
       "      <th>WORKTIME</th>\n",
       "      <th>INCOME</th>\n",
       "      <th>AGE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>9</td>\n",
       "      <td>3000</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>8</td>\n",
       "      <td>3000</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>8</td>\n",
       "      <td>3000</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>8.8</td>\n",
       "      <td>11</td>\n",
       "      <td>3000</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>15</td>\n",
       "      <td>5000</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9995</th>\n",
       "      <td>1</td>\n",
       "      <td>11.0</td>\n",
       "      <td>1</td>\n",
       "      <td>7000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9996</th>\n",
       "      <td>0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>1</td>\n",
       "      <td>10000</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9997</th>\n",
       "      <td>0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>18</td>\n",
       "      <td>17000</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9998</th>\n",
       "      <td>0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>8</td>\n",
       "      <td>10000</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9999</th>\n",
       "      <td>0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>7</td>\n",
       "      <td>6000</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9990 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      DEFAULT  INTEREST  BIDS  AMOUNT  CREDIT  HOUSE  CAR  HOUSE_L  CAR_L  \\\n",
       "0           0       5.0     9    3000       7      1    1        1      1   \n",
       "1           0      18.0     8    3000       3      0    0        0      0   \n",
       "2           0      12.0     8    3000       3      0    0        0      0   \n",
       "3           0       8.8    11    3000       7      1    1        1      1   \n",
       "4           0      15.0    15    5000       7      0    1        0      0   \n",
       "...       ...       ...   ...     ...     ...    ...  ...      ...    ...   \n",
       "9995        1      11.0     1    7000       1      1    0        0      0   \n",
       "9996        0      11.0     1   10000       3      0    0        0      0   \n",
       "9997        0      11.0    18   17000       3      1    0        1      0   \n",
       "9998        0      12.0     8   10000       2      0    0        0      0   \n",
       "9999        0       9.0     7    6000       3      1    1        0      0   \n",
       "\n",
       "      EDUCATION  WORKTIME  INCOME  AGE  \n",
       "0           3.0       2.0     6.0   33  \n",
       "1           3.0       4.0     4.0   37  \n",
       "2           3.0       4.0     4.0   37  \n",
       "3           3.0       2.0     6.0   33  \n",
       "4           3.0       2.0     3.0   33  \n",
       "...         ...       ...     ...  ...  \n",
       "9995        3.0       4.0     3.0   36  \n",
       "9996        1.0       2.0     4.0   28  \n",
       "9997        3.0       2.0     3.0   28  \n",
       "9998        2.0       1.0     3.0   30  \n",
       "9999        3.0       4.0     4.0   34  \n",
       "\n",
       "[9990 rows x 13 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "reg_data2=data2.dropna(subset=['EDUCATION','WORKTIME','INCOME'])\n",
    "reg_data2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题一：描述性统计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/_p/rfbd33cd5jggpfbv91zgdptr0000gn/T/ipykernel_27056/990800276.py:2: UserWarning: Pandas requires version '3.0.5' or newer of 'xlsxwriter' (version '3.0.3' currently installed).\n",
      "  descriptive_stats1.to_excel('outcome2.1.1.xlsx', index=False)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Collapse</th>\n",
       "      <th>Benign</th>\n",
       "      <th>Fraud</th>\n",
       "      <th>RegCapital</th>\n",
       "      <th>Capitaldeposit</th>\n",
       "      <th>Obtaininvest</th>\n",
       "      <th>Joinasso</th>\n",
       "      <th>Autobid</th>\n",
       "      <th>Transright</th>\n",
       "      <th>Riskdeposit</th>\n",
       "      <th>Thirdguarantee</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1000.000000</td>\n",
       "      <td>782.000000</td>\n",
       "      <td>782.000000</td>\n",
       "      <td>1000.000000</td>\n",
       "      <td>1000.000000</td>\n",
       "      <td>968.000000</td>\n",
       "      <td>968.000000</td>\n",
       "      <td>1000.000000</td>\n",
       "      <td>1000.00000</td>\n",
       "      <td>968.000000</td>\n",
       "      <td>968.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.782000</td>\n",
       "      <td>0.098465</td>\n",
       "      <td>0.246803</td>\n",
       "      <td>596.064330</td>\n",
       "      <td>0.191000</td>\n",
       "      <td>0.026860</td>\n",
       "      <td>0.054752</td>\n",
       "      <td>0.244000</td>\n",
       "      <td>0.17700</td>\n",
       "      <td>0.021694</td>\n",
       "      <td>0.034091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.413094</td>\n",
       "      <td>0.298134</td>\n",
       "      <td>0.431427</td>\n",
       "      <td>2328.221711</td>\n",
       "      <td>0.393286</td>\n",
       "      <td>0.161756</td>\n",
       "      <td>0.227613</td>\n",
       "      <td>0.429708</td>\n",
       "      <td>0.38186</td>\n",
       "      <td>0.145758</td>\n",
       "      <td>0.181557</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>300.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>50000.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Collapse      Benign       Fraud    RegCapital  Capitaldeposit  \\\n",
       "count  1000.000000  782.000000  782.000000   1000.000000     1000.000000   \n",
       "mean      0.782000    0.098465    0.246803    596.064330        0.191000   \n",
       "std       0.413094    0.298134    0.431427   2328.221711        0.393286   \n",
       "min       0.000000    0.000000    0.000000      2.000000        0.000000   \n",
       "25%       1.000000    0.000000    0.000000    100.000000        0.000000   \n",
       "50%       1.000000    0.000000    0.000000    300.000000        0.000000   \n",
       "75%       1.000000    0.000000    0.000000    500.000000        0.000000   \n",
       "max       1.000000    1.000000    1.000000  50000.000000        1.000000   \n",
       "\n",
       "       Obtaininvest    Joinasso      Autobid  Transright  Riskdeposit  \\\n",
       "count    968.000000  968.000000  1000.000000  1000.00000   968.000000   \n",
       "mean       0.026860    0.054752     0.244000     0.17700     0.021694   \n",
       "std        0.161756    0.227613     0.429708     0.38186     0.145758   \n",
       "min        0.000000    0.000000     0.000000     0.00000     0.000000   \n",
       "25%        0.000000    0.000000     0.000000     0.00000     0.000000   \n",
       "50%        0.000000    0.000000     0.000000     0.00000     0.000000   \n",
       "75%        0.000000    0.000000     0.000000     0.00000     0.000000   \n",
       "max        1.000000    1.000000     1.000000     1.00000     1.000000   \n",
       "\n",
       "       Thirdguarantee  \n",
       "count      968.000000  \n",
       "mean         0.034091  \n",
       "std          0.181557  \n",
       "min          0.000000  \n",
       "25%          0.000000  \n",
       "50%          0.000000  \n",
       "75%          0.000000  \n",
       "max          1.000000  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "descriptive_stats1 = data1[['Collapse', 'Benign','Fraud','RegCapital','Background','Capitaldeposit','Obtaininvest','Joinasso','Autobid','Transright','Riskdeposit','Thirdguarantee']].describe()\n",
    "descriptive_stats1.to_excel('outcome2.1.1.xlsx', index=False)\n",
    "descriptive_stats1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/_p/rfbd33cd5jggpfbv91zgdptr0000gn/T/ipykernel_27056/2208324730.py:3: UserWarning: Pandas requires version '3.0.5' or newer of 'xlsxwriter' (version '3.0.3' currently installed).\n",
      "  descriptive_stats2.to_excel('outcome2.1.2.xlsx', index=False)\n"
     ]
    }
   ],
   "source": [
    "descriptive_stats2 = data2[['DEFAULT', 'INTEREST','BIDS','AMOUNT','CREDIT','HOUSE','CAR','HOUSE_L','CAR_L','EDUCATION','WORKTIME','INCOME','AGE']].describe()\n",
    "descriptive_stats2\n",
    "descriptive_stats2.to_excel('outcome2.1.2.xlsx', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Background\n",
       "民营系     92.4\n",
       "国企背景     4.6\n",
       "上市公司     1.6\n",
       "风投系      1.4\n",
       "Name: count, dtype: float64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bg_counts = data1['Background'].value_counts()\n",
    "# 计算总频率\n",
    "total_count = len(data1['Background'])\n",
    "# 计算占比\n",
    "marriage_percentages = bg_counts / total_count * 100\n",
    "# 打印结果\n",
    "marriage_percentages"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题二："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimization terminated successfully.\n",
      "         Current function value: 0.330132\n",
      "         Iterations 9\n",
      "                           Logit Regression Results                           \n",
      "==============================================================================\n",
      "Dep. Variable:                DEFAULT   No. Observations:                 9990\n",
      "Model:                          Logit   Df Residuals:                     9980\n",
      "Method:                           MLE   Df Model:                            9\n",
      "Date:                Thu, 12 Dec 2024   Pseudo R-squ.:                  0.2236\n",
      "Time:                        19:13:22   Log-Likelihood:                -3298.0\n",
      "converged:                       True   LL-Null:                       -4247.9\n",
      "Covariance Type:            nonrobust   LLR p-value:                     0.000\n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "const          0.5155      0.212      2.427      0.015       0.099       0.932\n",
      "CREDIT        -1.8927      0.082    -23.044      0.000      -2.054      -1.732\n",
      "HOUSE          0.1438      0.073      1.968      0.049       0.001       0.287\n",
      "CAR           -0.4586      0.080     -5.708      0.000      -0.616      -0.301\n",
      "HOUSE_L       -0.3307      0.091     -3.633      0.000      -0.509      -0.152\n",
      "CAR_L          0.1620      0.134      1.207      0.228      -0.101       0.425\n",
      "EDUCATION     -0.4156      0.040    -10.426      0.000      -0.494      -0.337\n",
      "WORKTIME       0.0090      0.034      0.264      0.792      -0.058       0.076\n",
      "INCOME         0.1160      0.025      4.592      0.000       0.066       0.165\n",
      "AGE            0.0254      0.005      4.936      0.000       0.015       0.036\n",
      "==============================================================================\n"
     ]
    }
   ],
   "source": [
    "# 定义自变量（X）和因变量（y）\n",
    "X1 = reg_data2[['CREDIT','HOUSE','CAR','HOUSE_L','CAR_L','EDUCATION','WORKTIME','INCOME','AGE']]\n",
    "y1 = reg_data2['DEFAULT'] \n",
    "# 添加常数项以拟合截距\n",
    "X1 = sm.add_constant(X1) \n",
    "# 定义Logit模型\n",
    "logit_model = sm.Logit(y1, X1)\n",
    "# 拟合模型\n",
    "result = logit_model.fit()\n",
    "# 查看模型结果\n",
    "print(result.summary())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "进行多重共线性检验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     feature        VIF\n",
      "0      const  43.605240\n",
      "1     CREDIT   1.101509\n",
      "2      HOUSE   1.497020\n",
      "3        CAR   1.426349\n",
      "4    HOUSE_L   1.326349\n",
      "5      CAR_L   1.177347\n",
      "6  EDUCATION   1.072635\n",
      "7   WORKTIME   1.267157\n",
      "8     INCOME   1.203443\n",
      "9        AGE   1.396831\n"
     ]
    }
   ],
   "source": [
    "from statsmodels.stats.outliers_influence import variance_inflation_factor\n",
    "# 初始化VIF DataFrame\n",
    "vif_data = pd.DataFrame()\n",
    "vif_data['feature'] = X1.columns\n",
    "# 计算VIF\n",
    "vif_data['VIF'] = [variance_inflation_factor(X1.values, i) for i in range(X1.shape[1])]\n",
    "# 打印VIF DataFrame\n",
    "print(vif_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:                   BIDS   R-squared:                       0.173\n",
      "Model:                            OLS   Adj. R-squared:                  0.172\n",
      "Method:                 Least Squares   F-statistic:                     232.1\n",
      "Date:                Thu, 12 Dec 2024   Prob (F-statistic):               0.00\n",
      "Time:                        19:13:22   Log-Likelihood:                -50383.\n",
      "No. Observations:                9990   AIC:                         1.008e+05\n",
      "Df Residuals:                    9980   BIC:                         1.009e+05\n",
      "Df Model:                           9                                         \n",
      "Covariance Type:            nonrobust                                         \n",
      "==============================================================================\n",
      "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "const        -50.8110      2.479    -20.497      0.000     -55.670     -45.952\n",
      "CREDIT         1.8652      0.257      7.248      0.000       1.361       2.370\n",
      "HOUSE          1.6099      0.926      1.738      0.082      -0.206       3.426\n",
      "CAR            4.2582      0.918      4.637      0.000       2.458       6.059\n",
      "HOUSE_L       -7.1289      1.030     -6.924      0.000      -9.147      -5.111\n",
      "CAR_L         -7.1951      1.482     -4.854      0.000     -10.101      -4.290\n",
      "EDUCATION     -2.0042      0.475     -4.218      0.000      -2.936      -1.073\n",
      "WORKTIME       2.4355      0.426      5.721      0.000       1.601       3.270\n",
      "INCOME         9.2260      0.308     29.918      0.000       8.622       9.831\n",
      "AGE            0.8126      0.066     12.235      0.000       0.682       0.943\n",
      "==============================================================================\n",
      "Omnibus:                    11602.380   Durbin-Watson:                   1.743\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):          1282780.294\n",
      "Skew:                           6.139   Prob(JB):                         0.00\n",
      "Kurtosis:                      57.139   Cond. No.                         239.\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n"
     ]
    }
   ],
   "source": [
    "X2 = reg_data2[['CREDIT','HOUSE','CAR','HOUSE_L','CAR_L','EDUCATION','WORKTIME','INCOME','AGE']]\n",
    "y2 = reg_data2['BIDS'] \n",
    "# 添加常数项以拟合截距\n",
    "X2 = sm.add_constant(X2) \n",
    "# 定义Logit模型\n",
    "logit_model = sm.OLS(y2, X2)\n",
    "# 拟合模型\n",
    "result = logit_model.fit()\n",
    "# 查看模型结果\n",
    "print(result.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     feature        VIF\n",
      "0      const  43.605240\n",
      "1     CREDIT   1.101509\n",
      "2      HOUSE   1.497020\n",
      "3        CAR   1.426349\n",
      "4    HOUSE_L   1.326349\n",
      "5      CAR_L   1.177347\n",
      "6  EDUCATION   1.072635\n",
      "7   WORKTIME   1.267157\n",
      "8     INCOME   1.203443\n",
      "9        AGE   1.396831\n"
     ]
    }
   ],
   "source": [
    "vif_data = pd.DataFrame()\n",
    "vif_data['feature'] = X2.columns\n",
    "# 计算VIF\n",
    "vif_data['VIF'] = [variance_inflation_factor(X2.values, i) for i in range(X2.shape[1])]\n",
    "# 打印VIF DataFrame\n",
    "print(vif_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/_p/rfbd33cd5jggpfbv91zgdptr0000gn/T/ipykernel_27056/2463966981.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  reg_data1['Background']= reg_data1['Background'].apply(lambda x: 1 if x == '民营系' else 0)\n"
     ]
    }
   ],
   "source": [
    "reg_data1['Background']= reg_data1['Background'].apply(lambda x: 1 if x == '民营系' else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/_p/rfbd33cd5jggpfbv91zgdptr0000gn/T/ipykernel_27056/962669446.py:2: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.\n",
      "The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.\n",
      "\n",
      "For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.\n",
      "\n",
      "\n",
      "  reg_data1['Bankrupt_WDZJ'].fillna(max_value, inplace=True)\n",
      "/var/folders/_p/rfbd33cd5jggpfbv91zgdptr0000gn/T/ipykernel_27056/962669446.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  reg_data1['Bankrupt_WDZJ'].fillna(max_value, inplace=True)\n",
      "/var/folders/_p/rfbd33cd5jggpfbv91zgdptr0000gn/T/ipykernel_27056/962669446.py:3: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  reg_data1['Bankrupt_WDZJ'] = reg_data1['Bankrupt_WDZJ'].astype(int)\n"
     ]
    }
   ],
   "source": [
    "max_value = reg_data1['Bankrupt_WDZJ'].dropna().max()\n",
    "reg_data1['Bankrupt_WDZJ'].fillna(max_value, inplace=True)\n",
    "reg_data1['Bankrupt_WDZJ'] = reg_data1['Bankrupt_WDZJ'].astype(int)\n",
    "reg_data=reg_data1.copy()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Duration</th>\n",
       "      <th>Collapse</th>\n",
       "      <th>RegCapital</th>\n",
       "      <th>Background</th>\n",
       "      <th>Capitaldeposit</th>\n",
       "      <th>Obtaininvest</th>\n",
       "      <th>Joinasso</th>\n",
       "      <th>Autobid</th>\n",
       "      <th>Transright</th>\n",
       "      <th>Riskdeposit</th>\n",
       "      <th>Thirdguarantee</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1060</td>\n",
       "      <td>1</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>398</td>\n",
       "      <td>1</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>577</td>\n",
       "      <td>1</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>97</td>\n",
       "      <td>1</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>126</td>\n",
       "      <td>1</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>435</td>\n",
       "      <td>1</td>\n",
       "      <td>100.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1578</td>\n",
       "      <td>0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>115</td>\n",
       "      <td>1</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>655</td>\n",
       "      <td>1</td>\n",
       "      <td>100.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>439</td>\n",
       "      <td>1</td>\n",
       "      <td>50.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>968 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Duration  Collapse  RegCapital  Background  Capitaldeposit  Obtaininvest  \\\n",
       "0        1060         1       500.0           1               0           0.0   \n",
       "1         398         1       500.0           1               0           0.0   \n",
       "2         577         1       500.0           1               0           0.0   \n",
       "3          97         1       500.0           1               0           0.0   \n",
       "4         126         1         5.0           1               0           0.0   \n",
       "..        ...       ...         ...         ...             ...           ...   \n",
       "995       435         1       100.0           1               0           0.0   \n",
       "996      1578         0       100.0           1               0           0.0   \n",
       "997       115         1       500.0           1               0           0.0   \n",
       "998       655         1       100.0           1               0           0.0   \n",
       "999       439         1        50.0           1               0           0.0   \n",
       "\n",
       "     Joinasso  Autobid  Transright  Riskdeposit  Thirdguarantee  \n",
       "0         1.0        0           0          0.0             0.0  \n",
       "1         0.0        0           0          0.0             0.0  \n",
       "2         0.0        1           1          0.0             0.0  \n",
       "3         0.0        0           0          0.0             0.0  \n",
       "4         0.0        0           0          0.0             0.0  \n",
       "..        ...      ...         ...          ...             ...  \n",
       "995       0.0        0           0          0.0             0.0  \n",
       "996       0.0        1           0          0.0             0.0  \n",
       "997       0.0        1           0          0.0             0.0  \n",
       "998       0.0        0           0          0.0             0.0  \n",
       "999       0.0        0           0          0.0             0.0  \n",
       "\n",
       "[968 rows x 11 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "reg_data.dtypes\n",
    "def convert_int_to_datetime(int_date):\n",
    "    str_date = str(int_date)\n",
    "    return datetime.strptime(str_date, '%Y%m%d')\n",
    "reg_data['Bankrupt_WDZJ'] = reg_data1['Bankrupt_WDZJ'].apply(convert_int_to_datetime)\n",
    "reg_data['OnlineTime_YMD'] = reg_data1['OnlineTime_YMD'].apply(convert_int_to_datetime)\n",
    "reg_data['Duration']=(reg_data['Bankrupt_WDZJ']-reg_data['OnlineTime_YMD']).dt.days\n",
    "reg_data=reg_data[['Duration','Collapse','RegCapital','Background','Capitaldeposit','Obtaininvest','Joinasso','Autobid','Transright','Riskdeposit','Thirdguarantee']]\n",
    "reg_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "Pandas requires version '3.1.2' or newer of 'jinja2' (version '2.11.3' currently installed).",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/IPython/core/formatters.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m    343\u001b[0m             \u001b[0mmethod\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_real_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprint_method\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    344\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mmethod\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 345\u001b[0;31m                 \u001b[0;32mreturn\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    346\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    347\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/lifelines/utils/printer.py\u001b[0m in \u001b[0;36m_repr_latex_\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    183\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    184\u001b[0m     ):\n\u001b[0;32m--> 185\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_latex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    186\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    187\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_repr_html_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/lifelines/utils/printer.py\u001b[0m in \u001b[0;36mto_latex\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     60\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     61\u001b[0m             \u001b[0mcolumns\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msummary_df\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mintersection\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 62\u001b[0;31m         \u001b[0ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msummary_df\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstyle\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     63\u001b[0m         \u001b[0ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprecision\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecimals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     64\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_latex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36mstyle\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m   1440\u001b[0m         \u001b[0;31m`\u001b[0m\u001b[0mTable\u001b[0m \u001b[0mVisualization\u001b[0m \u001b[0;34m<\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0muser_guide\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mstyle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mipynb\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0;31m`\u001b[0m\u001b[0m_\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mmore\u001b[0m \u001b[0mexamples\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1441\u001b[0m         \"\"\"\n\u001b[0;32m-> 1442\u001b[0;31m         \u001b[0;32mfrom\u001b[0m \u001b[0mpandas\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformats\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstyle\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mStyler\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1443\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1444\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mStyler\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/pandas/io/formats/style.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     42\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpandas\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformats\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0msave_to_buffer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     43\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 44\u001b[0;31m \u001b[0mjinja2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mimport_optional_dependency\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"jinja2\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mextra\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"DataFrame.style requires jinja2.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     46\u001b[0m from pandas.io.formats.style_render import (\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/pandas/compat/_optional.py\u001b[0m in \u001b[0;36mimport_optional_dependency\u001b[0;34m(name, extra, errors, min_version)\u001b[0m\n\u001b[1;32m    162\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    163\u001b[0m             \u001b[0;32melif\u001b[0m \u001b[0merrors\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"raise\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 164\u001b[0;31m                 \u001b[0;32mraise\u001b[0m \u001b[0mImportError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    165\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    166\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mImportError\u001b[0m: Pandas requires version '3.1.2' or newer of 'jinja2' (version '2.11.3' currently installed)."
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>model</th>\n",
       "      <td>lifelines.CoxPHFitter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>duration col</th>\n",
       "      <td>'Duration'</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>event col</th>\n",
       "      <td>'Collapse'</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>baseline estimation</th>\n",
       "      <td>breslow</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>number of observations</th>\n",
       "      <td>968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>number of events observed</th>\n",
       "      <td>774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>partial log-likelihood</th>\n",
       "      <td>-4650.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time fit was run</th>\n",
       "      <td>2024-12-12 11:13:22 UTC</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div><table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th style=\"min-width: 12px;\"></th>\n",
       "      <th style=\"min-width: 12px;\">coef</th>\n",
       "      <th style=\"min-width: 12px;\">exp(coef)</th>\n",
       "      <th style=\"min-width: 12px;\">se(coef)</th>\n",
       "      <th style=\"min-width: 12px;\">coef lower 95%</th>\n",
       "      <th style=\"min-width: 12px;\">coef upper 95%</th>\n",
       "      <th style=\"min-width: 12px;\">exp(coef) lower 95%</th>\n",
       "      <th style=\"min-width: 12px;\">exp(coef) upper 95%</th>\n",
       "      <th style=\"min-width: 12px;\">cmp to</th>\n",
       "      <th style=\"min-width: 12px;\">z</th>\n",
       "      <th style=\"min-width: 12px;\">p</th>\n",
       "      <th style=\"min-width: 12px;\">-log2(p)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>RegCapital</th>\n",
       "      <td>0.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.30</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Background</th>\n",
       "      <td>0.55</td>\n",
       "      <td>1.73</td>\n",
       "      <td>0.18</td>\n",
       "      <td>0.19</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1.21</td>\n",
       "      <td>2.46</td>\n",
       "      <td>0.00</td>\n",
       "      <td>3.02</td>\n",
       "      <td>&lt;0.005</td>\n",
       "      <td>8.63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Capitaldeposit</th>\n",
       "      <td>-1.30</td>\n",
       "      <td>0.27</td>\n",
       "      <td>0.14</td>\n",
       "      <td>-1.57</td>\n",
       "      <td>-1.04</td>\n",
       "      <td>0.21</td>\n",
       "      <td>0.35</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-9.57</td>\n",
       "      <td>&lt;0.005</td>\n",
       "      <td>69.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Obtaininvest</th>\n",
       "      <td>0.05</td>\n",
       "      <td>1.05</td>\n",
       "      <td>0.28</td>\n",
       "      <td>-0.49</td>\n",
       "      <td>0.59</td>\n",
       "      <td>0.61</td>\n",
       "      <td>1.80</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.17</td>\n",
       "      <td>0.86</td>\n",
       "      <td>0.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Joinasso</th>\n",
       "      <td>-0.57</td>\n",
       "      <td>0.57</td>\n",
       "      <td>0.23</td>\n",
       "      <td>-1.02</td>\n",
       "      <td>-0.12</td>\n",
       "      <td>0.36</td>\n",
       "      <td>0.89</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-2.48</td>\n",
       "      <td>0.01</td>\n",
       "      <td>6.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Autobid</th>\n",
       "      <td>-0.21</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.09</td>\n",
       "      <td>-0.39</td>\n",
       "      <td>-0.03</td>\n",
       "      <td>0.68</td>\n",
       "      <td>0.97</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-2.35</td>\n",
       "      <td>0.02</td>\n",
       "      <td>5.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Transright</th>\n",
       "      <td>-0.54</td>\n",
       "      <td>0.58</td>\n",
       "      <td>0.11</td>\n",
       "      <td>-0.76</td>\n",
       "      <td>-0.33</td>\n",
       "      <td>0.47</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-5.04</td>\n",
       "      <td>&lt;0.005</td>\n",
       "      <td>21.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Riskdeposit</th>\n",
       "      <td>-0.12</td>\n",
       "      <td>0.89</td>\n",
       "      <td>0.27</td>\n",
       "      <td>-0.64</td>\n",
       "      <td>0.40</td>\n",
       "      <td>0.53</td>\n",
       "      <td>1.49</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.45</td>\n",
       "      <td>0.65</td>\n",
       "      <td>0.62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Thirdguarantee</th>\n",
       "      <td>-0.20</td>\n",
       "      <td>0.82</td>\n",
       "      <td>0.23</td>\n",
       "      <td>-0.64</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.53</td>\n",
       "      <td>1.28</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.87</td>\n",
       "      <td>0.38</td>\n",
       "      <td>1.39</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><br><div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Concordance</th>\n",
       "      <td>0.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Partial AIC</th>\n",
       "      <td>9319.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>log-likelihood ratio test</th>\n",
       "      <td>292.87 on 9 df</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>-log2(p) of ll-ratio test</th>\n",
       "      <td>189.59</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "<lifelines.CoxPHFitter: fitted with 968 total observations, 194 right-censored observations>\n",
       "             duration col = 'Duration'\n",
       "                event col = 'Collapse'\n",
       "      baseline estimation = breslow\n",
       "   number of observations = 968\n",
       "number of events observed = 774\n",
       "   partial log-likelihood = -4650.83\n",
       "         time fit was run = 2024-12-12 11:13:22 UTC\n",
       "\n",
       "---\n",
       "                coef exp(coef)  se(coef)  coef lower 95%  coef upper 95% exp(coef) lower 95% exp(coef) upper 95%\n",
       "covariate                                                                                                       \n",
       "RegCapital      0.00      1.00      0.00           -0.00            0.00                1.00                1.00\n",
       "Background      0.55      1.73      0.18            0.19            0.90                1.21                2.46\n",
       "Capitaldeposit -1.30      0.27      0.14           -1.57           -1.04                0.21                0.35\n",
       "Obtaininvest    0.05      1.05      0.28           -0.49            0.59                0.61                1.80\n",
       "Joinasso       -0.57      0.57      0.23           -1.02           -0.12                0.36                0.89\n",
       "Autobid        -0.21      0.81      0.09           -0.39           -0.03                0.68                0.97\n",
       "Transright     -0.54      0.58      0.11           -0.76           -0.33                0.47                0.72\n",
       "Riskdeposit    -0.12      0.89      0.27           -0.64            0.40                0.53                1.49\n",
       "Thirdguarantee -0.20      0.82      0.23           -0.64            0.25                0.53                1.28\n",
       "\n",
       "                cmp to     z      p  -log2(p)\n",
       "covariate                                    \n",
       "RegCapital        0.00  0.30   0.77      0.38\n",
       "Background        0.00  3.02 <0.005      8.63\n",
       "Capitaldeposit    0.00 -9.57 <0.005     69.61\n",
       "Obtaininvest      0.00  0.17   0.86      0.21\n",
       "Joinasso          0.00 -2.48   0.01      6.26\n",
       "Autobid           0.00 -2.35   0.02      5.72\n",
       "Transright        0.00 -5.04 <0.005     21.01\n",
       "Riskdeposit       0.00 -0.45   0.65      0.62\n",
       "Thirdguarantee    0.00 -0.87   0.38      1.39\n",
       "---\n",
       "Concordance = 0.67\n",
       "Partial AIC = 9319.66\n",
       "log-likelihood ratio test = 292.87 on 9 df\n",
       "-log2(p) of ll-ratio test = 189.59"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "X3 = reg_data1[['RegCapital','Background','Capitaldeposit','Obtaininvest','Joinasso','Autobid','Transright','Riskdeposit','Thirdguarantee']]\n",
    "covariates = X3\n",
    "from lifelines.statistics import logrank_test\n",
    "from lifelines import CoxPHFitter\n",
    "# 创建CoxPHFitter对象并拟合模型\n",
    "cph = CoxPHFitter()\n",
    "cph.fit(reg_data, duration_col='Duration', event_col='Collapse') \n",
    "# 打印模型摘要\n",
    "cph.print_summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          feature       VIF\n",
      "0      RegCapital  1.067827\n",
      "1      Background  1.423915\n",
      "2  Capitaldeposit  1.404760\n",
      "3    Obtaininvest  1.122652\n",
      "4        Joinasso  1.254685\n",
      "5         Autobid  1.539639\n",
      "6      Transright  1.410402\n",
      "7     Riskdeposit  1.081873\n",
      "8  Thirdguarantee  1.103995\n"
     ]
    }
   ],
   "source": [
    "vif_data = pd.DataFrame()\n",
    "vif_data['feature'] = X3.columns\n",
    "# 计算VIF\n",
    "vif_data['VIF'] = [variance_inflation_factor(X3.values, i) for i in range(X3.shape[1])]\n",
    "# 打印VIF DataFrame\n",
    "print(vif_data)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
